package ferus.tigris.livewallpapers.mechanism;

import android.graphics.Canvas;
import android.graphics.Point;

public class ComposeGear implements IGear{

	IGear gear1, gear2;
	public ComposeGear(IGear g1, IGear g2) {
		gear1 = g1;
		gear2 = g2;
		gear1.addObserver(this);
		//gear2.addObserver(this);
	}

	@Override
	public void update() {}

	@Override
	public void addObserver(IGear gear) {}

	@Override
	public void tick(float rotate, float radius) {
		if(gear1.radius() == radius) {
			gear2.tick(-rotate, gear2.radius());
		} else if(gear2.radius() == radius) {
			gear1.tick(rotate, gear1.radius());
		}
	}

	@Override
	public void setPosition(Point p) {
		gear1.setPosition(p);
		gear2.setPosition(p);
	}

	@Override
	public float radius() {
		return Math.max(gear1.radius(), gear2.radius());
	}

	@Override
	public void interactWith(IGear gear) {}

	@Override
	public void drawBackground(Canvas c) {
		gear1.drawBackground(c);
		gear2.drawBackground(c);
	}
	
	@Override
	public void draw(Canvas c) {
		gear1.draw(c);
		gear2.draw(c);
	}

	@Override
	public void drawForeground(Canvas c) {
		gear1.drawForeground(c);
		gear2.drawForeground(c);
	}

}
